
# -*- coding:utf-8 -*-
import os, sys, re
# 获取osma输出
omreport = os.popen('omreport system summary')
result = omreport.read()
result = result.strip()

# 将结果以行分割,生成列表,列表的元素为单个item的key与value组成的字符串
items = result.split('\n')

# 去除无效的item
items_new = []
for ele in items:
    if re.match('^\w[\s\w]+?: \w', ele):
        items_new.append(ele)

# item列表转换为字典
item_dict = {}
for ele in items_new:
    key, value = ele.split(': ')
    key = key.strip()
    key = key.replace(' ', '_')
    item_dict[key] = value

# 根据命令行输入得出结果
if sys.argv[1] == 'list':
    print(item_dict.keys())
else:
    item_key = sys.argv[1]
    print(item_dict[item_key])
